<template>
  <div class="diary">
    <a-row class="comm-main" type="flex" justify="center" :gutter="5">
      <a-col class="comm-left content" :xs="20" :sm="14" :md="13" :lg="14" :xl="10">
        <a-card class="box-card" shadow="hover">
          <a-timeline>
            <a-timeline-item v-for="item in essayList" :key="item.id">
              <div class="date">{{ item.addTime }}</div>
              <div class="title">{{ item.content }}</div>
              <img :src="item.essay_url" alt />
            </a-timeline-item>
          </a-timeline>
          <a-pagination
            v-model="current"
            :total="total"
            :page-size="pageSize"
            show-less-items
            class="paging"
            @change="onChange"
          ></a-pagination>
        </a-card>
      </a-col>
      <a-col class="comm-left info" :xs="0" :sm="6" :md="5" :lg="10" :xl="5">
        <a-affix>
          <a-card class="box-card" shadow="hover">
            <Author />
          </a-card>
          <a-card class="advert" shadow="hover">
            <Advert />
          </a-card>
        </a-affix>
      </a-col>
    </a-row>
    <Footer />
  </div>
</template>

<script>
import Author from "../Author/index";
import Advert from "../Advert/index";
import Footer from "../Footer/index";
export default {
  data() {
    return {
      essayList: [],
      current: 1, // 当前页数
      total: 10, // 数据总数
      pageSize: 5, // 改变这个变量后台就可以改变每页显示的条数，这个图省事
    };
  },
  created() {
    this.getEssayList();
  },
  components: {
    Author,
    Advert,
    Footer,
  },
  methods: {
    async getEssayList() {
      let { data: res } = await this.$http.get("/default/getEssayList", {
        params: { current: this.current, pageSize: this.pageSize },
      });
      this.essayList = res.data;
      this.total = res.total;
    },
    // 页码改变的回调
    onChange(current, pageSize) {
      this.current = current;
      this.getEssayList();
    },
  },
};
</script>

<style lang="less" scoped>
@keyframes fade-left {
  0% {
    transform: translateX(-80px);
    opacity: 0;
  }
  25% {
    transform: translateX(-60px);
    opacity: 0.2;
  }
  50% {
    transform: translateX(-40px);
    opacity: 0.3;
  }
  75% {
    transform: translateX(-20px);
    opacity: 0.5;
  }
  100% {
    transform: translateX(0px);
    opacity: 1;
  }
}
@keyframes fade-right {
  0% {
    transform: translateX(80px);
    opacity: 0;
  }
  25% {
    transform: translateX(60px);
    opacity: 0.2;
  }
  50% {
    transform: translateX(40px);
    opacity: 0.4;
  }
  75% {
    transform: translateX(20px);
    opacity: 0.6;
  }
  100% {
    transform: translateX(0px);
    opacity: 1;
  }
}
.diary {
  overflow: hidden;
  .content {
    animation: fade-left 0.3s ease-out;
    .ant-card {
      background: rgba(255, 255, 255, 0.7);
    }
  }
  .info {
    animation: fade-right 0.3s ease-out;
    .ant-card {
      background: rgba(255, 255, 255, 0.6);
    }
  }
  .ant-col {
    .box-card {
      .ant-card-body {
        .ant-timeline {
          .ant-timeline-item {
            margin-top: 1.2rem;
            .date {
              color: #999;
            }
            .title {
              font-size: 1rem;
              text-shadow: 1px 1px 10px blue;
              margin: 0.5rem 0;
            }
            img {
              max-width: 100%;
              border-radius: 5px;
            }
          }
        }
      }
    }
  }
}
.ant-list {
  .ant-list-header {
    font-size: 1.1rem;
    font-weight: bold;
  }
}
.list-title {
  font-size: 1.3rem;
  color: #1e90ff;
  padding: 0 0.5rem;
  cursor: pointer;
  transition: color 0.5s;
  &&:hover {
    color: #112c69;
  }
}
.list-icon {
  user-select: none;
}
.list-context {
  padding: 0.5rem;
  font-size: 1rem;
  color: #999 !important;
}
.list-icon {
  padding: 0.5rem 0;
  color: #aaa;
  span {
    display: inline-block;
    padding: 0 5px;
    i {
      text-indent: 3px;
    }
  }
}
.list-img {
  img {
    width: 100%;
  }
}
.preview {
  margin-top: 1em;
  display: flex;
  justify-content: flex-end;
  .preview-content {
    margin-right: 20px;
    color: #1890ff;
    cursor: pointer;
  }
  .preview-icon {
    margin-right: 0.5em;
    color: #bbbbbb;
  }
}
.paging {
  text-align: end;
}
</style>